<?php

namespace app\extensions\helper;

class Menu extends \lithium\template\Helper
{
    public function add($output, $url = "#", $controller = array(), $action = array())
    {
        $controllers = is_array($controller) ? $controller : array($controller);
        $actions = is_array($action) ? $action : array($action);

        $matchController = false;
        if(count($controller) == 0)
            $matchController = true;
        else
            foreach($controllers as $c)
                if($c == $this->_context->request()->controller)
                    $matchController = true;

        $matchAction = false;
        if(count($action) == 0)
            $matchAction = true;
        else
            foreach($actions as $a)
                if($a == $this->_context->request()->action)
                    $matchAction = true;

        $selected = ($matchController and $matchAction) ? 'class="selected"' : '';

        return '<a href="'.$url.'" '.$selected.'>'.$output.'</a>';
    }
}
